<?php  
class mcomment extends CI_model{ 
   public function __construct(){
        parent::__construct();
        $this->load->database();
    }
    
    public function get_CommnetById($cm_Product_Id) {
        $this->db->where('cm_Product_Id', $cm_Product_Id);
        $query = $this->db->get('comment');
        return $query->result_array();
    }

    public function insert($array_data) {
      date_default_timezone_set('Asia/Ho_Chi_Minh');
      $today = date("Y/m/d h:i:s a");
      $isLogin =  $array_data['cm_isLogin'] == 'true'? true: false;



      $data = array(
        'cm_Product_Id' => $array_data['cm_Product_Id'],
        'cm_Parent' => $array_data['cm_Id'],
        'cm_EmailVisit'    => $array_data['cm_Email'],
        'cm_NameVisit'  => $array_data['cm_Name'],
        'cm_Detail' => $array_data['cm_Content'],
        'cm_User' => 0,
        'cm_Date' => $today,
        'cm_IsVisit' => $array_data['cm_IsMember'] == 'true'? 1: 0
      );

      if($isLogin) {
          $data['cm_NameVisit']  = $this->session->userdata('users_FullName');
          $data['cm_User'] = $this->session->userdata('users_Id');
          $data['cm_EmailVisit'] = $this->session->userdata('users_Email');
          
      }
      $this->db->insert('comment', $data);
    }
} 
?>